//
//  MockDataService.swift
//  WeChatClient
//
//  Created by AI Assistant on 2025/10/31.
//

import Foundation
import Combine

class MockDataService: ObservableObject {
    static let shared = MockDataService()
    
    private init() {}
    
    // MARK: - Mock Users
    func getMockUsers() -> [User] {
        return [
            User(userName: "zhang_san", displayName: "张三", avatar: "person.crop.circle.fill", signature: "生活就像海洋，只有意志坚强的人才能到达彼岸", phoneNumber: "13800138001", isOnline: true),
            User(userName: "li_si", displayName: "李四", avatar: "person.crop.circle.fill", signature: "今天也要加油哦～", phoneNumber: "13800138002", isOnline: false),
            User(userName: "wang_wu", displayName: "王五", avatar: "person.crop.circle.fill", signature: "做自己喜欢的事情", phoneNumber: "13800138003", isOnline: true),
            User(userName: "zhao_liu", displayName: "赵六", avatar: "person.crop.circle.fill", signature: "Keep calm and carry on", phoneNumber: "13800138004", isOnline: true),
            User(userName: "qian_qi", displayName: "钱七", avatar: "person.crop.circle.fill", signature: "一切都会好起来的", phoneNumber: "13800138005", isOnline: false),
            User(userName: "sun_ba", displayName: "孙八", avatar: "person.crop.circle.fill", signature: "阳光总在风雨后", phoneNumber: "13800138006", isOnline: true),
            User(userName: "zhou_jiu", displayName: "周九", avatar: "person.crop.circle.fill", signature: "努力工作，快乐生活", phoneNumber: "13800138007", isOnline: true),
            User(userName: "wu_shi", displayName: "吴十", avatar: "person.crop.circle.fill", signature: "世界那么大，我想去看看", phoneNumber: "13800138008", isOnline: false)
        ]
    }
    
    // MARK: - Mock Conversations
    func getMockConversations() -> [Conversation] {
        let users = getMockUsers()
        var conversations: [Conversation] = []
        
        for (index, user) in users.enumerated() {
            var messages: [ChatMessage] = []
            
            // 添加一些示例消息
            switch index {
            case 0:
                messages = [
                    ChatMessage(content: "你好，最近怎么样？", senderId: user.userName, senderName: user.displayName, timestamp: Date().addingTimeInterval(-3600)),
                    ChatMessage(content: "还不错，你呢？", senderId: User.currentUser.userName, senderName: User.currentUser.displayName, timestamp: Date().addingTimeInterval(-3500)),
                    ChatMessage(content: "我也挺好的，明天有空吗？", senderId: user.userName, senderName: user.displayName, timestamp: Date().addingTimeInterval(-300))
                ]
            case 1:
                messages = [
                    ChatMessage(content: "😊", type: .emoji, senderId: user.userName, senderName: user.displayName, timestamp: Date().addingTimeInterval(-7200)),
                    ChatMessage(content: "哈哈，心情不错啊", senderId: User.currentUser.userName, senderName: User.currentUser.displayName, timestamp: Date().addingTimeInterval(-7100))
                ]
            case 2:
                messages = [
                    ChatMessage(content: "工作顺利吗？", senderId: user.userName, senderName: user.displayName, timestamp: Date().addingTimeInterval(-1800)),
                    ChatMessage(content: "还行，就是有点忙", senderId: User.currentUser.userName, senderName: User.currentUser.displayName, timestamp: Date().addingTimeInterval(-1700)),
                    ChatMessage(content: "注意休息哦", senderId: user.userName, senderName: user.displayName, timestamp: Date().addingTimeInterval(-600))
                ]
            default:
                messages = [
                    ChatMessage(content: "Hello!", senderId: user.userName, senderName: user.displayName, timestamp: Date().addingTimeInterval(-Double(index) * 1000))
                ]
            }
            
            let unreadCount = index < 3 ? Int.random(in: 0...5) : 0
            let conversation = Conversation(participant: user, messages: messages, unreadCount: unreadCount)
            conversations.append(conversation)
        }
        
        return conversations.sorted { conv1, conv2 in
            (conv1.lastMessageTime ?? Date.distantPast) > (conv2.lastMessageTime ?? Date.distantPast)
        }
    }
    
    // MARK: - Mock Moments
    func getMockMoments() -> [Moment] {
        let users = getMockUsers()
        var moments: [Moment] = []
        
        // 添加各种类型的朋友圈内容
        moments.append(Moment(
            user: users[0],
            content: "今天天气真好，出来走走心情都变好了 ☀️",
            contentType: .text,
            timestamp: Date().addingTimeInterval(-3600)
        ))
        
        moments.append(Moment(
            user: users[1],
            content: "今天的晚餐，自己下厨真香！",
            contentType: .singleImage,
            images: ["fork.knife.circle.fill"],
            timestamp: Date().addingTimeInterval(-7200)
        ))
        
        moments.append(Moment(
            user: users[2],
            content: "周末和朋友们一起出游，玩得很开心～",
            contentType: .multipleImages,
            images: [
                "photo.on.rectangle.angled",
                "camera.macro",
                "photo.artframe",
                "camera.aperture",
                "photo.stack.fill",
                "photo.tv"
            ],
            timestamp: Date().addingTimeInterval(-86400)
        ))
        
        moments.append(Moment(
            user: users[3],
            content: "加班到很晚，但是项目终于完成了！💪",
            contentType: .text,
            timestamp: Date().addingTimeInterval(-172800)
        ))
        
        moments.append(Moment(
            user: users[4],
            content: "分享一首好听的歌",
            contentType: .video,
            videoUrl: "sample_video",
            timestamp: Date().addingTimeInterval(-259200)
        ))
        
        // 添加更多朋友圈内容示例
        moments.append(Moment(
            user: users[5],
            content: "健身打卡第30天！💪 坚持就是胜利",
            contentType: .multipleImages,
            images: ["figure.run", "heart.fill", "flame.fill"],
            timestamp: Date().addingTimeInterval(-345600)
        ))
        
        moments.append(Moment(
            user: users[6],
            content: "今晚的夕阳特别美",
            contentType: .singleImage,
            images: ["sun.max.fill"],
            timestamp: Date().addingTimeInterval(-432000)
        ))
        
        moments.append(Moment(
            user: users[7],
            content: "刚看完的电影，强烈推荐！",
            contentType: .video,
            videoUrl: "movie_clip",
            timestamp: Date().addingTimeInterval(-518400)
        ))
        
        // 添加一些点赞和评论
        moments[0].likes.append(users[1])
        moments[0].likes.append(users[2])
        moments[0].comments.append(MomentComment(user: users[1], content: "是啊，阳光明媚～", timestamp: Date().addingTimeInterval(-3000)))
        
        moments[1].likes.append(users[0])
        moments[1].likes.append(users[3])
        moments[1].comments.append(MomentComment(user: users[0], content: "看起来很好吃！", timestamp: Date().addingTimeInterval(-6600)))
        
        return moments.sorted { $0.timestamp > $1.timestamp }
    }
    
    // MARK: - Emoji Data
    func getEmojiCategories() -> [String: [String]] {
        return [
            "笑脸": ["😀", "😃", "😄", "😁", "😆", "😅", "🤣", "😂", "🙂", "🙃", "😉", "😊", "😇"],
            "爱心": ["🥰", "😍", "🤩", "😘", "😗", "😚", "😙", "😋", "😛", "😜", "🤪", "😝", "🤑"],
            "表情": ["🤗", "🤭", "🤫", "🤔", "🤐", "🤨", "😐", "😑", "😶", "😏", "😒", "🙄", "😬"],
            "手势": ["👍", "👎", "👊", "✊", "🤛", "🤜", "🤞", "✌️", "🤟", "🤘", "👌", "🤏", "👈"]
        ]
    }
}
